home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / btsys.arc / BTIRED.C < prev    next >
Text File  |  1984-12-14  |  1KB  |  61 lines

  1. /*    btired        */
  2. #include <stdio.h>
  3. #include <btextern.h>
  4. int btired (filhand, key)
  5. int filhand;
  6. char key[];
  7.  
  8. /*    random read function    */
  9.  
  10. {
  11.     int i, j, k, occurs, klength, recno;
  12.     char *cp;
  13.  
  14. printf("BTIRED filhand %d key %s\n", filhand, key);
  15.  
  16. klength = btfilar[filhand].keylen;    /* get key length */
  17. occurs = (LBLEN - 1) / (klength + 3);
  18. recno = btfilar[filhand].root;
  19.  
  20. /* get root record    */
  21. if ((i = btread (filhand, recno)))
  22.     BTSETCOD (filhand, recno, i);    /* set read error */
  23.  
  24. /*     start looping forever    */
  25. while (1)    {
  26.     if (*((char *)btfilar[filhand].filbuf + (LBLEN -1)) == 'N') {
  27.     ip1 = btfilar[filhand].filbuf;
  28.     cp1 = (char *)(btfilar[filhand].filbuf + occurs);
  29.  
  30.     while ((i = strcmp (cp1, "")) != 0
  31.     && (k = strcmp (cp1, key)) == -1)
  32.     {
  33.     ip1++;
  34.     cp1 += (klength + 1);
  35.     }
  36.     recno = *ip1;
  37.     if ((i = btread (filhand, recno)))
  38.     BTSETCOD (filhand, recno, i);    /* set read error */
  39.     }
  40.  
  41.     else    {
  42.     j = 0;
  43.     ip1 = btfilar[filhand].filbuf;
  44.     cp1 = btfilar[filhand].ikeyptr;
  45.     while (*ip1 != NULL)    {
  46.     if ((i = strcmp (cp1, key)) == 0)    {
  47.         gdatapt = *ip1;
  48.         return (0);
  49.  
  50.         }
  51.     else    {
  52.     
  53.         ip1++;
  54.         cp1 += (klength + 1);
  55.     };    /* end else */
  56.     };
  57.     return (-1);
  58.     };    /* end else */
  59. }     /* end while */
  60. }    /* end btired */
  61.